import request from "@/utils/request";
import type {PermissionDTO} from "@/types/dto/PermissionDTO";
import type {Result} from "@/types/common/Result";
import type {PermissionQuery} from "@/types/query/PermissionQuery";
import type {PageResult} from "@/types/common/PageResult";
import type {PermissionVO} from "@/types/vo/PermissionVO";
import type {RoleQuery} from "@/types/query/RoleQuery";
import type {RoleVO} from "@/types/vo/RoleVO";
import type {UserDTO} from "@/types/dto/UserDTO";
import type {UserQuery} from "@/types/query/UserQuery";

/**
 * 新增权限
 * @param params
 */
export function addPermission(params: PermissionDTO) {
  return request.post<Result<any>>(`/admin/auth/permission/add`, params);
}

/**
 * 删除权限
 * @param ids
 */

export function deletePermissionByIds(ids: string) {
  return request.delete<Result<any>>(`/admin/auth/permission/delete/${ids}`);
}

/**
 * 获取分页权限列表
 * @param params
 */
export function getPermissionList(params: PermissionQuery) {
  return request.post<Result<PageResult<PermissionVO>>>(`/admin/auth/permission/page`, params);
}

/**
 * 获取权限不分页
 */
export function getPermissionListNoPage() {
  return request.get<Result<PermissionVO[]>>(`/admin/auth/permission/list`);
}

/**
 * 新增角色
 */
export function addRole(params: PermissionDTO) {
  return request.post<Result<any>>(`/admin/auth/role/add`, params);
}

/**
 *获取角色详情
 */
export function getRoleDetail(roleId: number) {
  return request.get<Result<RoleVO>>(`/admin/auth/role/get/${roleId}`);
}

/**
 * 分页获取角色列表
 */
export function getRoleList(params: RoleQuery) {
  return request.post<Result<PageResult<RoleVO>>>(`/admin/auth/role/page`, params);
}

/**
 * 获取角色不分页
 */
export function getRoleListNoPage() {
  return request.get<Result<RoleVO[]>>(`/admin/auth/role/list`);
}

/**
 * 获取角色拥有的权限
 */
export function getPermissionByRoleId(roleId: number) {
  return request.get<Result<PermissionVO[]>>(`/admin/auth/role/getPermission/${roleId}`);
}

/**
 * 获取角色没有的权限
 */
export function getNotPermissionByRoleId(roleId: number) {
  return request.get<Result<PermissionVO[]>>(`/admin/auth/role/getNotPermission/${roleId}`);
}

/**
 * 给角色分配权限
 */
export function assignPermission(roleId: number, permissionIds: string) {
  return request.post<Result<any>>(`/admin/auth/role/assignPermission/`, {},{
    params:{
      permissionIds,
      roleId
    }
  });
}

/**
 * 给角色移除权限
 */
export function removePermission(roleId: number, permissionIds: string) {
  return request.post<Result<any>>(`/admin/auth/role/removePermission`, {},{
    params:{
      permissionIds,
      roleId
    }
  });
}

// 更新角色权限
export function updateRolePermission(roleId: number, permissionIds: string) {
  return request.post<Result<any>>(`/admin/auth/role/updateRolePermission`, {},{
    params:{
      permissionIds,
      roleId
    }
  });
}

/**
 * 删除角色
 */

export function deleteRoleByIds(ids: string) {
  return request.delete<Result<any>>(`/admin/auth/role/delete/${ids}`);
}

/**
 * 删除用户
 */
export function deleteUserByIds(ids: string) {
  return request.delete<Result<any>>(`/admin/auth/user/delete/${ids}`);
}

/**
 * 修改用户
 */
export function updateUser(params: UserDTO) {
  return request.post<Result<any>>(`/admin/auth/user/update`, params);
}

/**
 * 获取用户列表
 * @param params
 */
export function getUserList(params: UserQuery) {
  return request.post<Result<PageResult<UserDTO>>>(`/admin/auth/user/page`, params);
}

/**
 * 获取用户详情
 * @param userId
 */
export function getUserDetail(userId: number) {
  return request.get<Result<UserDTO>>(`/admin/auth/user/get/${userId}`);
}

/**
 * 获取用户角色
 * @param userId
 */
export function getUserRoleList(userId: number) {
  return request.get<Result<RoleVO[]>>(`/admin/auth/user/getRoles/${userId}`);
}

/**
 *  获取用户没有的角色
 * @param userId
 */
export function getUserNotRoleList(userId: number) {
  return request.get<Result<RoleVO[]>>(`/admin/auth/user/getNotRoles/${userId}`);
}

/**
 * 给用户分配角色
 */
export function assignRole(userId: number, roleIds: string) {
  return request.post<Result<any>>(`/admin/auth/user/assignRole/`, {},{
    params:{
      roleIds,
      userId
    }
  });
}

/**
 *  移除用户角色
 * @param userId
 * @param roleIds
 */
export function removeRole(userId: number, roleIds: string) {
  return request.post<Result<any>>(`/admin/auth/user/removeRole/`, {},{
    params:{
      roleIds,
      userId
    }
  });
}

/**
 * 更新用户角色
 */

export function updateUserRole(userId: number, roleIds: string) {
  return request.post<Result<any>>(`/admin/auth/user/updateUserRole`, {},{
    params:{
      roleIds,
      userId
    }
  });
}





